package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DzKsjieguoMapper;
import com.ruoyi.system.domain.DzKsjieguo;
import com.ruoyi.system.service.IDzKsjieguoService;


import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.mapper.DzHuiyuanMapper;
import com.ruoyi.system.domain.DzHuiyuan;
import com.ruoyi.system.service.IDzHuiyuanService;

/**
 * 考试结果Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-02
 */
@Service
public class DzKsjieguoServiceImpl implements IDzKsjieguoService 
{
    @Autowired
    private DzKsjieguoMapper dzKsjieguoMapper;

    @Autowired
    private ISysRoleService sysRoleService;

    @Autowired
    private IDzHuiyuanService dzHuiyuanService;

    /**
     * 查询考试结果
     * 
     * @param jgId 考试结果主键
     * @return 考试结果
     */
    @Override
    public DzKsjieguo selectDzKsjieguoByJgId(Long jgId)
    {
        return dzKsjieguoMapper.selectDzKsjieguoByJgId(jgId);
    }

    /**
     * 查询考试结果列表
     * 
     * @param dzKsjieguo 考试结果
     * @return 考试结果
     */
    @Override
    public List<DzKsjieguo> selectDzKsjieguoList(DzKsjieguo dzKsjieguo)
    {

        //权限控制
        SysUser user=  SecurityUtils.getLoginUser().getUser();
        List<SysRole> listRole= sysRoleService.selectRolesByUserId(user.getUserId());
        int datascope = 5;
        for(SysRole role:listRole){
            if( role.getDataScope()!=null&&Integer.parseInt(role.getDataScope())<datascope){
                datascope=Integer.parseInt(role.getDataScope());
            }
        }
        dzKsjieguo.setDatascope(datascope);
        if(datascope==4){
            dzKsjieguo.setCheckDeptId(user.getDeptId());
        }
        if(datascope==5){
            DzHuiyuan huiyuan =  dzHuiyuanService.selectDzHuiyuanByDn(user.getPhonenumber());
            if(huiyuan!=null){
                dzKsjieguo.setCheckHuiyuanId(huiyuan.getId());
            }else{
                dzKsjieguo.setCheckHuiyuanId(0l);
            }

        }
        return dzKsjieguoMapper.selectDzKsjieguoList(dzKsjieguo);
    }

    @Override
    public List<DzKsjieguo> selectDzKsjieguoListWeb(DzKsjieguo dzKsjieguo)
    {
        return dzKsjieguoMapper.selectDzKsjieguoList(dzKsjieguo);
    }

    /**
     * 新增考试结果
     * 
     * @param dzKsjieguo 考试结果
     * @return 结果
     */
    @Override
    public int insertDzKsjieguo(DzKsjieguo dzKsjieguo)
    {
        return dzKsjieguoMapper.insertDzKsjieguo(dzKsjieguo);
    }

    /**
     * 修改考试结果
     * 
     * @param dzKsjieguo 考试结果
     * @return 结果
     */
    @Override
    public int updateDzKsjieguo(DzKsjieguo dzKsjieguo)
    {
        return dzKsjieguoMapper.updateDzKsjieguo(dzKsjieguo);
    }

    /**
     * 批量删除考试结果
     * 
     * @param jgIds 需要删除的考试结果主键
     * @return 结果
     */
    @Override
    public int deleteDzKsjieguoByJgIds(Long[] jgIds)
    {
        return dzKsjieguoMapper.deleteDzKsjieguoByJgIds(jgIds);
    }

    /**
     * 删除考试结果信息
     * 
     * @param jgId 考试结果主键
     * @return 结果
     */
    @Override
    public int deleteDzKsjieguoByJgId(Long jgId)
    {
        return dzKsjieguoMapper.deleteDzKsjieguoByJgId(jgId);
    }
}
